package com.coco.dao.Impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.coco.dao.CategoryDao;
import com.coco.model.Category;
import com.coco.utils.C3P0Util;

public class CategoryDaoImpl implements CategoryDao{

	@Override
	public List<Category> findAllCategory() throws SQLException {
		QueryRunner qr = new QueryRunner(C3P0Util.getDataSource());
		return qr.query("select * from category", new BeanListHandler<>(Category.class));
			
	}

	@Override
	public Category findById(String sql, String cid) throws SQLException {
		QueryRunner qr = new QueryRunner(C3P0Util.getDataSource());
		return qr.query(sql, new BeanHandler<>(Category.class),cid);
			
	}

}

	